<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>与卿婚纱公司</title><link rel="stylesheet" href="layui/css/layui.css" />
</head>
<body>
<jsp:include page="yemeiServlet"></jsp:include>
<div>

    <header class="header-article-list">
    <div style="width: 650px; position: relative; left:35%;">
        <h1>在线留言</h1>
            </div>
    </header>
<div>
<div style="width: 650px; position: relative; left:35%;">
  <form class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>姓名</label>
					<div class="layui-input-inline">
						<input type="text" name="name" required lay-verify="required"
							placeholder="请输入员工姓名" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>电话</label>
					<div class="layui-input-inline">
						<input type="text" name="uphone" required lay-verify="required"
							placeholder="请输入电话" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>邮箱</label>
					<div class="layui-input-inline">
						<input type="text" name="email" required lay-verify="required"
							placeholder="请输入邮箱" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label"><span style="color: red;">*</span>内容</label>
					<div class="layui-input-inline">
						<textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formDemo">立即添加</button>
					</div>
				</div>
			</form>
			</div>
			<script type="text/javascript" src="layui/layui.js"></script>
			<script>
				//加载了layui的form模块
				layui.use('form', function() {
					var form = layui.form;
					var $ = layui.jquery; //引入jquery
					//监听提交
					form.on('submit(formDemo)', function(data) {
						var d = data.field; //表单中的数据，定义一个对象来接收
						//通过ajax向数据库提交数据了
						d.method = "getAdd";
						console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
						var url = 'messageServlet';
						//确保数据没有问题就进行ajax提交了
						$.post(url, d, function(data) {
							if (data.count > 0) {
								console.log('添加成功');
								window.location.reload();//当窗口关闭之后刷新页面
								var index = parent.layer
										.getFrameIndex(window.name); //获取当前窗口的name
								parent.layer.close(index); //关闭窗口
								
							}
						}, "json");
						return false;
					});
				});
			</script>
</div>
</div>

<jsp:include page="yejiaoServlet"></jsp:include>
</body>
</html>